<?php 
/**
 * 
 * Controlador de Tipo de Outbound
 * @author Natanael 
 * 
 */

class Tipooutbound extends Controller {
	
	public function __construct()
	{
		parent::Controller();
		$this->load->database();
		$this->load->model(array('mtipo_outbound'));
	}
	
	public function index()
	{
		$this->load->view('main',array('content_page'=>'list_tipooutbound','menutop'=>0));
	}
	
	
	
	public function data()
	{
		
		$page = $this->input->post('page') ? $this->input->post('page') : 1; // Pagina Actual o 1 por default
		$sortname = 'IdPais';
		$sortorder = 'asc'; // Orden (asc|desc)
		$limit = $this->input->post('rows') ? $this->input->post('rows') : 10;
		$start = $limit * $page - $limit;
		if($start < 0) $start = 0;
		
		header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
		header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
		header("Cache-Control: no-cache, must-revalidate" );
		header("Pragma: no-cache" );
		
		$records = $this->mtipo_outbound->loadOutbound();
		
		$totalRecords = count($records);
		
		$totalPages = ceil($totalRecords/$limit);
		if ($page > $totalPages) $page = $totalPages;

		$json_output = array(
		'page'		=> $page,
		'total'		=> $totalPages,
		'records'	=> $totalRecords,
		'rows'		=> array()
		);
		
		if ($totalRecords > 0) {
			
			foreach ($records as $tipoOutbound)
			{
			   	 $array = $json_output['rows'][] = array(
			   	          'id'       => $tipoOutbound->getIdOutbound(),
			   	          'OutboundTipo'     => $tipoOutbound->getTipoOutbound()
			   	          );
			}
			
		}
		
		echo json_encode($json_output);
		
	}
	
	public function add()
	{
		$this->load->view('main',array('content_page'=>'add_tipooutbound','menutop'=>0));
	}
	
    public function edit($id)
	{
		$registro = $this->mtipo_outbound->loadOutboundById($id);
		$this->load->view('main',array('content_page'=>'edit_tipooutbound','menutop'=>0,'registro'=>$registro));
	}
	
	public function save()
	{
		$id = @$this->input->post('id');
		
		$date = array(
		              'OutboundTipo'   =>$this->input->post('nombre')
		             );
		             
         if ($id > 0) {
         	 
         	if ( $this->mtipo_outbound->editRegistro($date,$id) ==  true) {
			        redirect('tipooutbound');
		        } 
         	   
         
         }else{
         	
         	 	if ( $this->mtipo_outbound->addRegistro($date) ==  true) {
			        redirect('tipooutbound');
		        } 
         	
         }
		                          
		             
	}
	
	public function delete()
	{
		$id = $this->input->post('delete_rows');
		
		if ($this->mtipo_outbound->deleteRegistro($id)) {
			
		} 
	}
	
}
?>